package com.shopmall.controller.goods;

import com.shopmall.common.ResponseData;
import com.shopmall.goods.entity.GoodsRule;
import com.shopmall.goods.service.IGoodsRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("goodsRule")
public class GoodsRuleController extends ResponseData {
    @Autowired
    private IGoodsRuleService goodsRuleService;

    @PostMapping("pageList")
    public Object pageList(@RequestBody GoodsRule goodsRule) {
        return success(goodsRuleService.pageList(goodsRule));
    }

    @PostMapping("ruleList")
    public Object ruleList() {
        return success(goodsRuleService.ruleList());
    }

    @PostMapping("addOrUpdate")
    public Object addOrUpdate(@RequestBody GoodsRule goodsRule) {
        int i = goodsRuleService.addOrUpdate(goodsRule);
        if(i>0){
            return success("成功");
        }
        return failed("失败");
    }

    @PostMapping("deleteById")
    public Object deleteById(Integer id) {
        int i = goodsRuleService.deleteById(id);
        if(i>0){
            return success("成功");
        }
        return failed("失败");

    }
}
